home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / TUTORIAL / 0222.ZIP / DUMPFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1982-08-28  |  2KB  |  73 lines

  1. { dump file in hex from file in to file out }
  2. { Scott Loftesness - 8/28/82 }
  3. {$include:'a:filkqq.inc'}
  4. {$include:'a:filuqq.inc'}
  5. program dumpfile(in_file,output);
  6.   uses filkqq, filuqq;
  7. {$line+}
  8.  
  9. const
  10.     ENDFILE = -1;
  11.     NEWLINE = 10;   { ASCII value }
  12.     bpl = 16;      { Number of bytes to dump per line }
  13.  
  14. type
  15.     ascii = set of char;
  16.  
  17. var in_file: file of byte;
  18.     i: integer;
  19.     inbyte: byte;
  20.     addr: word;
  21.     l: lstring(255);
  22.     error: word;
  23.     line: lstring(5+(bpl*3));
  24.     bufr: lstring(bpl*2);
  25.     flag: boolean;
  26.     c: char;
  27.     asc: ascii;
  28.     aline: lstring(bpl);
  29.  
  30. { getparm -- get parms from command line }
  31. procedure getparm;
  32. begin
  33.     error:=ppmuqq(0,adr null,l);
  34.     writeln('This was on the command line:',l)
  35. end; {getparm}
  36.  
  37. { dump -- dump in_file file to output in hex format }
  38. procedure dump;
  39. begin
  40.     addr:=0;
  41.     line:=null;
  42.     aline:=null;
  43.     asc:=[' '..'~'];
  44.     reset(in_file);
  45.     writeln('Hex Dump of file: ',in_file.name);
  46.     writeln;
  47.     while (not eof(in_file)) do begin
  48.       flag:=encode(line,addr:4:16);
  49.       addr:=addr+bpl;
  50.       concat(line,' ');
  51.         for i:=1 to bpl do begin
  52.             inbyte:=in_file^;
  53.             flag:=encode(bufr,inbyte:2:16);
  54.             concat(line,bufr);
  55.             concat(line,' ');
  56.             c:=chr(inbyte);
  57.             if c in asc then concat(aline,c)
  58.                 else concat(aline,'.');
  59.             get(in_file);
  60.             if eof(in_file) then break;
  61.         end;
  62.       line.len:=5+bpl*3;
  63.       writeln(line,' ',aline);
  64.       copystr(' ',line);
  65.       line:=null;
  66.       aline:=null;
  67.     end
  68. end; { dump }
  69.  
  70. begin   { main program }
  71.     dump
  72. end.
  73.